package com.bida.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bida.core.entity.User;
import com.bida.service.UserService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;

/**
 * 
 * @author chenli
 *
 */
@RestController
@RequestMapping("rest/user")
@Api(value = "user interfaces", description = "", position = 1)
public class UserController {
    private static Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserService UserService;
    
    
    @ApiOperation(value = "get a user", position = 11)
    @RequestMapping(value="/{id}", method=RequestMethod.GET, headers = { "Accept=application/json" })
    public User view(@PathVariable("id") String id, HttpServletRequest request) {
        User user = new User();
        user.setId(id);
        user.setName("zhang");
        return user;
    }
    
    @ApiOperation(value = "create a user", position = 12)
    @RequestMapping(method=RequestMethod.POST, headers = { "Accept=application/json" })
    public void addUser(@RequestBody User user, HttpServletRequest request) {
//        User user = new User();
//        user.setName("zhang");
	user.setId(null);
        UserService.addUser(user);
    }
}
